<?php
function statlog($presence, $pageid, $pageview=1) {
	if(!isset($_SESSION["session_uid"]) && !defined("ADMINMODE")) {
		create_session($presence);
	}
	mysql_query("INSERT INTO ". $GLOBALS["db_pref"] ."statistics_pageviews SET pageid='". $pageid ."', sessionid='". $_SESSION["session_uid"] ."', pageview='". $pageview ."'");
}

function create_session($presence) {
	$ua=$_SERVER["HTTP_USER_AGENT"];
	$userbrowser=get_userbrowser($ua);
	$referer="";
	if(isset($_SERVER["HTTP_REFERER"])) {
		$referer=$_SERVER["HTTP_REFERER"];
	}
	if (mysql_query("INSERT INTO ". $GLOBALS["db_pref"] ."statistics_sessions SET ip='". $_SERVER["REMOTE_ADDR"] ."', hostname='". gethostbyaddr($_SERVER["REMOTE_ADDR"]) ."', referer='". $referer ."', browser='". $userbrowser[0] ."', vendor='". $userbrowser[1] ."', system='". get_system($ua) ."', serverurl='". $_SERVER["HTTP_HOST"] ."', browserstring='". $ua ."'")) {
		$_SESSION["session_uid"]=mysql_insert_id();
	}
}

function get_userbrowser($browser) {
	$browsername="unbekannt";
	$hersteller="Andere";

	if(eregi("LYNX", $browser)) { $browsername = "Lynx"; $hersteller = "Andere"; }
	elseif(eregi("Safari", $browser)) { $browsername = "Safari"; $hersteller = "Apple"; }
	elseif(eregi("Firefox", $browser)) { $browsername = "Firefox"; $hersteller = "Mozilla"; }
	elseif(eregi("Opera", $browser)) { $browsername = "Opera"; $hersteller = "Opera"; }
	elseif(eregi("Mozilla/4.07|Mozilla/4.5|Mozilla/4.7", $browser)) { $browsername = "Netscape Navigator 4.x"; $hersteller = "Netscape"; }
	elseif(eregi("MSIE 4", $browser)) { $browsername = "Internet Explorer 4.x"; $hersteller = "Microsoft"; }
	elseif(eregi("MSIE 5.5", $browser)) { $browsername = "Internet Explorer 5.5x"; $hersteller = "Microsoft"; }
	elseif(eregi("MSIE 5|MSIE 5.0", $browser)) { $browsername = "Internet Explorer 5.x"; $hersteller = "Microsoft"; }
	elseif(eregi("MSIE 6", $browser)) { $browsername = "Internet Explorer 6.x"; $hersteller = ""; }
	elseif(eregi("Netscape6", $browser)) { $browsername = "Netscape Navigator 6.x"; $hersteller = "Mozilla"; }
	elseif(eregi("Netscape/7.01|Netscape/7.02", $browser)) { $browsername = "Netscape Navigator 7.0x"; $hersteller = "Mozilla"; }
	elseif(eregi("Netscape/7", $browser)) { $browsername = "Netscape Navigator 7.x"; $hersteller = "Mozilla"; }
	elseif(eregi("Gecko", $browser)) { $browsername = "Gecko"; $hersteller = "Mozilla"; }
	elseif(eregi("bot", $browser)) { $browsername = "Suchmaschinen Robot"; $hersteller = "Andere"; }

	return array($browsername, $hersteller);
}

function get_system($browser) {
	$system="unbekannt";

	if(eregi("Windows 3.1", $browser)) $system = 'Windows 3.1'; 
	elseif(eregi("Windows 95|Win95", $browser))$system = 'Windows 95';
	elseif(eregi("Windows 98|Win98", $browser))$system = 'Windows 98';
	elseif(eregi("Windows NT 4.0", $browser))$system = 'Windows NT 4.0';
	elseif(eregi("Windows NT 5.0", $browser))$system = 'Windows NT 5.0';
	elseif(eregi("Windows XP", $browser))$system = 'Windows XP';
	elseif(eregi("Win 9x|Windows ME", $browser))$system = 'Windows ME';
	elseif(eregi("Windows NT 5.1", $browser))$system = 'Windows XP';
	elseif(eregi("Windows NT|WinNT", $browser))$system = 'Windows NT';
	elseif(eregi("Macintosh", $browser))$system = 'Macintosh';
	elseif(eregi("Mac_PowerPC", $browser))$system = 'Mac_PowerPC';
	elseif(eregi("Mac OS X", $browser))$system = 'Mac OS X';
	elseif(eregi("Linux", $browser))$system = 'Linux';
	elseif(eregi("bot", $browser))$system = 'Robot' ;

	return $system;
}
?>